package com.songlanyun.modules.group.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.songlanyun.common.drive.RootEntity;
import com.songlanyun.common.utils.SpringContextUtils;
import com.songlanyun.common.validator.group.AddGroup;
import com.songlanyun.common.validator.group.UpdateGroup;
import com.songlanyun.modules.category.entity.SystemProductCategoryEntity;
import com.songlanyun.modules.group.service.ProductGoodsGroupService;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.*;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 商家店铺商品分组表（只用来在商家店铺内展示）
 * 
 * @author lubo
 * @email sunlightcs@gmail.com
 * @date 2020-11-03 12:57:25
 */
@Data
@TableName("yxt_product_goods_group")
//@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
public class ProductGoodsGroupEntity extends RootEntity<Long, ProductGoodsGroupEntity> implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 * 
	 */
	@TableId
	@NotNull(message="修改时必须指定商品分组Id",groups = {UpdateGroup.class})
	@Null(message = "新增时不能指定商品分组Id",groups = {AddGroup.class})
	private Long id;
	/**
	 * 店铺id
	 */
	@NotNull( message = "新增时店铺id必须设置",groups = {AddGroup.class})
	private Long shopId;
	/**
	 * 上级分组
	 */

	private Long parentId;
	/**
	 * 分组名称
	 */
	@NotBlank(message="商品分组名称不能为空",groups = {AddGroup.class,UpdateGroup.class})
	@Length(min = 1,max = 20,message = "商品分组名称长度在1-20个字",groups = {AddGroup.class,UpdateGroup.class})
	private String name;
	/**
	 * 图标
	 */
	@Length(max = 500,message = "商品分组图标名称长度在300个字",groups = {AddGroup.class,UpdateGroup.class})
	private String coverImage;
	/**
	 * 介绍
	 */
	@Length(max = 200,message = "分类说明长度在1-200个字",groups = {AddGroup.class,UpdateGroup.class})
	private String introduction;
	/**
	 * 分组的顺序
	 */
	@Max(value = 999999,message = "顺序值最大999999",groups = {AddGroup.class,UpdateGroup.class})
	@Min(value = 0,message = "最小顺序值是0",groups = {AddGroup.class,UpdateGroup.class})
	private Integer orderIndex;

	/**
	 * 
	 */
	@TableField(fill = FieldFill.INSERT)
	private Date createTime;
	/**
	 * 
	 */
	@TableField(fill = FieldFill.INSERT_UPDATE)
	private Date updateTime;



	@Override
	public Long getIdentity() {
		return getId();
	}



	/**
	 * 获得所有子分组
	 * @return
	 */
	@JsonIgnore
	public List<ProductGoodsGroupEntity> loadChildren()
	{
		return ((ProductGoodsGroupService) SpringContextUtils.getBean("productGoodsGroupService")).getChildren(this.getShopId(),this.getId());
	}
}
